<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户园区列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <input  type="hidden" name="id" id="id" th:value="${id}">
                <div class="select-list">
                    <ul>

                        <li>
                            角色名称：<input type="text" name="roleName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
<!--            <a class="btn btn-success" onclick="addAreaRole()">-->
<!--                <i class="fa fa-plus"></i> 应用角色模板-->
<!--            </a>-->
            <a class="btn btn-success" onclick="addRole()" >
                <i class="fa fa-plus"></i> 新建园区角色
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "sso/area/";
    var prefix1 = ctx + "sso/role/";
    $(function () {
        var options = {
            url: prefix+"/areaByRoleList",
            columns: [
                {
                    field: 'role_id',
                    title: '角色ID'
                },
                {
                    field: 'role_name',
                    title: '角色名称'
                },
                {
                    field: 'role_key',
                    title: '角色权限'
                },
                {
                    field: 'role_sort',
                    title: '显示顺序',
                    sortable: true
                },
                {
                    field: 'status',
                    title: '角色状态',
                    formatter: function (value, row, index) {
                        if (row.status == 1) {
                            return '<span class="label label-danger">停用</span> ';
                        } else {
                            return '<span class="label label-success">正常</span>  ';
                        }
                    }
                },
                {
                    field: 'create_time',
                    title: '创建时间'
                }
                ,
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if (row.role_id != 1) {
                            var actions = [];
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="authUser(\'' + row.role_id +'\')"><i class="fa fa-user"></i>分配用户</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="editRole(\'' + row.role_id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                            actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="delStaffRole(\'' + row.role_id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            return actions.join('');
                        } else {
                            return "";
                        }
                    }
                }
               ]
        };
        $.table.init(options);
    });
    /* 角色管理-分配用户 */
    function authUser(roleId) {
        var url =  'sso/area/areaUser?roleId=' + roleId;
        $.modal.openTab("分配用户", url);
    }


    /* 修改 */
    function editRole(roleId)  {
        var url = prefix1 + '/edit?roleId=' + roleId;
        $.modal.open("修改", url);
    }


    function delStaffRole(roleId)  {
        //删除所有
        $.modal.confirm("确认要删除角色吗？", function() {
            $.operate.post(prefix1 + "/delAllRole", { "roleId": roleId});
        })
    }

    function addRole() {
        var url = prefix+'/addRole/' + $("#id").val();
        $.modal.open("添加角色", url);
    }

    /* 绑定园区角色 */
    function addAreaRole() {
        var url = ctx + 'sso/role/addAreaRole/' + $("#id").val();
        $.modal.open("分配用户", url);
    }


</script>
</body>
</html>